home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / objects in c ƒ / Name Sources / Binding.c next >
Encoding:
C/C++ Source or Header  |  1989-03-01  |  2.1 KB  |  112 lines  |  [TEXT/KAHL]

  1. /*    
  2.  *        Binding abstract class
  3.  *
  4.  *        a key - value binding pair.  
  5.  *
  6.  *            Copyright © John Wainwright 1988
  7.  *
  8.  *    SuperClasses :
  9.  *
  10.  *  Instance Vars :
  11.  *                    key
  12.  *                    value
  13.  *    Class Vars :
  14.  *    
  15.  *    Methods :
  16.  *                    new k v            - creates a Binding
  17.  *                    isKey k            - is this the key of the binding by == ?
  18.  *                    isKeyEqual k    - is this the key of the binding by equal
  19.  *                    set v            - set the value part
  20.  *                    get                - get the value part
  21.  *
  22.  *    Class Methods :
  23.  *
  24.  */
  25.  
  26. #include "oic.h"
  27. #include "generics.h"
  28.  
  29. class         Binding;                /* the Binding class             */
  30.  
  31. struct Binding_i                    /* Binding instance structure    */
  32. {
  33.     object    key;                    /* key                            */
  34.     object    value;                    /* value                        */
  35. };
  36. typedef struct Binding_i Binding_i;
  37.  
  38. /* -------------------- Binding Instance methods ------------------- */
  39.  
  40. method object
  41. _new(self, b, ba)                /* initialise a new binding            */
  42.     object                self;
  43.     register Binding_i    *b;
  44.     register struct { object k, v; } *ba;
  45. {
  46.     b->key = ba->k;
  47.     b->value = ba->v;
  48.     
  49.     return self;
  50. }
  51.  
  52.  
  53. method int
  54. _isKey(self, b, keyp)            /* is 'key' the binding key            */
  55.     object                self;
  56.     register Binding_i    *b;
  57.     register object        *keyp;
  58. {
  59.     return (b->key == *keyp);
  60. }
  61.  
  62. method int
  63. _isKeyEqual(self, b, keyp)        /* is 'key' the binding key by 'equal'    */
  64.     object                self;
  65.     register Binding_i    *b;
  66.     register object        *keyp;
  67. {
  68.     return (int)equal(b->key, *keyp);
  69. }
  70.  
  71. method object
  72. _valueOf(self, b)                /* get value part                        */
  73.     object                self;
  74.     register Binding_i    *b;
  75. {
  76.     return b->value;
  77. }
  78.  
  79. method object
  80. _keyOf(self, b)                    /* get key part                            */
  81.     object                self;
  82.     register Binding_i    *b;
  83. {
  84.     return b->key;
  85. }
  86.  
  87. method
  88. _set(self, b, valp)                /* set value part                        */
  89.     object                self;
  90.     register Binding_i    *b;
  91.     register object        *valp;
  92. {
  93.     b->value = *valp;
  94. }
  95.  
  96. /* ------------------- Init the Binding class ---------------------- */
  97.  
  98. InitBindingClass()
  99. {
  100.     Binding = NewClass(sizeof(Binding_i), 0, "Binding", END);
  101.     AddMethods(Binding,
  102.         newGeneric,         _new,
  103.         isKeyGeneric,         _isKey,
  104.         isKeyEqualGeneric,     _isKeyEqual,
  105.         valueOfGeneric,     _valueOf,
  106.         keyOfGeneric,         _keyOf,
  107.         getGeneric,         _valueOf,
  108.         setGeneric,         _set,
  109.         END);
  110. }
  111.  
  112.